package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HotelsMapper;
import com.ruoyi.system.domain.Hotels;
import com.ruoyi.system.service.IHotelsService;

/**
 * 酒店Service业务层处理
 *
 * @author Y.C
 * @date 2024-02-21
 */
@Service
public class HotelsServiceImpl  extends ServiceImpl<HotelsMapper,Hotels> implements IHotelsService
{
    @Autowired
    private HotelsMapper hotelsMapper;

    /**
     * 查询酒店
     *
     * @param hotelId 酒店主键
     * @return 酒店
     */
    @Override
    public Hotels selectHotelsByHotelId(Long hotelId)
    {
        return hotelsMapper.selectHotelsByHotelId(hotelId);
    }

    /**
     * 查询酒店列表
     *
     * @param hotels 酒店
     * @return 酒店
     */
    @Override
    public List<Hotels> selectHotelsList(Hotels hotels)
    {
        return hotelsMapper.selectHotelsList(hotels);
    }

    /**
     * 新增酒店
     *
     * @param hotels 酒店
     * @return 结果
     */
    @Override
    public int insertHotels(Hotels hotels)
    {
        hotels.setCreateTime(DateUtils.getNowDate());
        return hotelsMapper.insertHotels(hotels);
    }

    /**
     * 修改酒店
     *
     * @param hotels 酒店
     * @return 结果
     */
    @Override
    public int updateHotels(Hotels hotels)
    {
        hotels.setUpdateTime(DateUtils.getNowDate());
        return hotelsMapper.updateHotels(hotels);
    }

    /**
     * 批量删除酒店
     *
     * @param hotelIds 需要删除的酒店主键
     * @return 结果
     */
    @Override
    public int deleteHotelsByHotelIds(Long[] hotelIds)
    {
        return hotelsMapper.deleteHotelsByHotelIds(hotelIds);
    }

    /**
     * 删除酒店信息
     *
     * @param hotelId 酒店主键
     * @return 结果
     */
    @Override
    public int deleteHotelsByHotelId(Long hotelId)
    {
        return hotelsMapper.deleteHotelsByHotelId(hotelId);
    }

    @Override
    public List<Hotels> selectHotelIdAndName() {
        LambdaQueryWrapper<Hotels> hotelsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        hotelsLambdaQueryWrapper.select(Hotels::getHotelId,Hotels::getHotelName);
        List<Hotels> hotels = hotelsMapper.selectList(hotelsLambdaQueryWrapper);
        if (hotels.size() == 0){
            throw new RuntimeException("没有酒店信息");
        }
        return hotels;

    }
}
